package com.qian.ddj.web.controller;

import com.qian.api.ddj.model.ChangeCard;
import com.qian.api.ddj.service.IChangeCardService;
import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.web.system.security.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ddj/changeCard")
@Api(tags = "修改用户银行卡信息")
public class ChangeCardController {

    @Autowired
    private IChangeCardService changeCardService;

    @GetMapping("/all")
    @ApiOperation("后台修改银行卡申请列表")
    public PageResp<ChangeCard> allList(PageReq pageReq) {
        PageResp<ChangeCard> page = changeCardService.findAll(pageReq);
        return page;
    }

    @GetMapping
    @ApiOperation("用户修改银行卡申请列表")
    public PageResp<ChangeCard> list(PageReq pageReq) {
        ChangeCard changeCard = new ChangeCard();
        changeCard.setUserId(SecurityUtils.getUserId());
        PageResp<ChangeCard> page = changeCardService.findAll(changeCard, pageReq);
        return page;
    }

    @PostMapping("/save")
    @ApiOperation("提交申请")
    public void save(ChangeCard changeCard) {
        changeCard.setUserId(SecurityUtils.getUserId());
        changeCardService.save(changeCard);
    }
    @GetMapping("/cancel")
    @ApiOperation("撤销申请")
    public void cancel(ChangeCard changeCard){
        changeCard.setUserId(SecurityUtils.getUserId());
        changeCardService.cancel(changeCard);

    }


    @GetMapping("/allow/{id}")
    @ApiOperation("同意修改")
    public void allow(@PathVariable Long id) {
        changeCardService.allow(id);
    }

    @GetMapping("/notAllow/{id}")
    @ApiOperation("不同意修改")
    public void notAllow(@PathVariable Long id) {
        changeCardService.notAllow(id);
    }

    @GetMapping("/findByUserId")
    public List<ChangeCard> findByuserId(){

        return changeCardService.findByUserId(SecurityUtils.getUserId());
    }
    @GetMapping("/info")
    @ApiOperation("用户提交的最新一条数据")
    public ChangeCard info(){
       ChangeCard changeCard =  changeCardService.checkChangeCardCondition(SecurityUtils.getUserId());
        return changeCard;
    }

}
